﻿using System;
using System.Collections.Generic;

namespace Com.FoxGlobal.Daniel.Midea.TemplateService
{

    public enum WebServiceModuleCode
    {
        Default=0,
        Journals = 1000,
        ODS = 2000
    }

    public enum WebServiceErrorCode
    {
        Success = 0,
        Error_Login_Failture = 1001,
        Error_Logout_Failture = 1002,
        Error_Extract_Journals_Failtrue = 2001,
        Error_Extract_Journals_Read_Failture = 2002,
        Error_Load_Journals_Failtrue = 3001,
        Error_Load_Journals_Read_Failture = 3002,
        Error_Delete_Journals_Read_Failture = 4001,
        Error_Extract_Dimension_Failture = 5001,
        Error_ValidateAccount=6001,

        Error_Update_Failture = 201001,
        Error_Retrieve_Failture = 201002,
        Error_Template_Error = 201003,
        Error_Security_Not_Enough = 201004
    }

    public class WebServiceException : Exception
    {
        public WebServiceResult Result;

        public WebServiceException(WebServiceResult result)
        {
            Result = result;
            Logging.WriteLog(LoggingLevel.ERROR, "Result={0}", Result);
        }

        public WebServiceException(WebServiceErrorCode errorCode, string result)
        {
            Result = new WebServiceResult(WebServiceModuleCode.Default, errorCode, result);
            Logging.WriteLog(LoggingLevel.ERROR, "ErrorCode={0}, Result={1}", errorCode, result);
        }
    }

    public class WebServiceResult
    {
        public int ModuleID;
        public int ErrorCode;
        public string Result;

        public WebServiceResult()
        {
            ModuleID = (int)WebServiceModuleCode.Journals;
            ErrorCode = (int)WebServiceErrorCode.Success;
            Result = "";

            //Logging.WriteLog(LoggingLevel.DEBUG, "ModuleID={0}, ErrorCode={1}, Result={2}", ModuleID, ErrorCode, Result);
        }

        public WebServiceResult(WebServiceModuleCode code, WebServiceErrorCode errorCode, string result)
        {
            ModuleID = (int)code;
            ErrorCode = (int)errorCode;
            Result = result;

            //Logging.WriteLog(LoggingLevel.DEBUG, "ModuleID={0}, ErrorCode={1}, Result={2}", ModuleID, ErrorCode, Result);
        }

    }

    [Serializable]
    public class ComplexWebServiceResult
    {
        public int ModuleID;
        public int ErrorCode;
        public string Result;

        public List<String> ListString = new List<String>(new String[] { "A", "B", "C", "D" });
        //public Dictionary<String, String> DictStringString = new Dictionary<String, String>();
        public WebServiceResult InnerResult = new WebServiceResult(WebServiceModuleCode.Default, WebServiceErrorCode.Success, "Inner Result");

        public ComplexWebServiceResult()
        {
            ModuleID = (int)WebServiceModuleCode.Journals;
            ErrorCode = (int)WebServiceErrorCode.Success;
            Result = "";

            //Logging.WriteLog(LoggingLevel.DEBUG, "ModuleID={0}, ErrorCode={1}, Result={2}", ModuleID, ErrorCode, Result);
        }

        public ComplexWebServiceResult(WebServiceModuleCode code, WebServiceErrorCode errorCode, string result)
        {
            ModuleID = (int)code;
            ErrorCode = (int)errorCode;
            Result = result;

            //Logging.WriteLog(LoggingLevel.DEBUG, "ModuleID={0}, ErrorCode={1}, Result={2}", ModuleID, ErrorCode, Result);
        }

    }

}